{php include wl_template('common/header');}
<ul class="nav nav-tabs" id="myTab">
	<li class="active"><a href="#">添加大礼包</a></li>
</ul>
<div class="app-content">
	<div class="app-form">
		<form action="" method="post" class="form-horizontal form form-validate" id="commentForm">
			<div class="tab-content">
				<div class="tab-pane  active" id="tab_rush">
					<div class="panel panel-default">
						<div class="panel-heading">大礼包信息</div>
						<div class="panel-body">
							{if !is_store()}
							<div class="form-group">
								<label class="col-sm-2 control-label">选择商户</label>
								<div class="col-sm-9">
									<div class='input-group'>
										<div class="input-group ">
											<input type="text" class="form-control col-sm-9" id="namemerchant" name="" value="{$package['storename']}" style="width: 460px;" disabled>
											<input type="hidden" value="{$package['merchantid']}" id="firstid" />
											<span class="input-group-btn">
                       						<button class="btn btn-default" type="button" onclick="popwin = $('#modal-module-merchant').modal();">选择商家</button></span>
										</div>
										<div class="input-group " style="margin-top:.5em;">
											<input type="hidden" value="{$package['merchantid']}" name="package[merchantid]" id="sidmerchant">
											<img src="{if empty($package['logo'])}../web/resource/images/nopic.jpg{else}{php echo tomedia($package['logo'])}{/if}" class="img-responsive img-thumbnail" width="150" id="imgmerchant" />
											<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除" onclick="remove_merchant(this)">×</em>
										</div>
									</div>
								</div>
							</div>
							{/if}
							<div class="form-group"  style="display: block;">
								<label class="col-sm-2 control-label">礼包标题</label>
								<div class="col-sm-9">
									<input type="text" name="package[title]" class="form-control" value="{$package['title']}" placeholder="填写活动名称，默认与商户名称相同" id="storetitle" />
								</div>
							</div>
							<div class="form-group"  style="display: block;">
								<label class="col-sm-2 control-label">礼包价值</label>
								<div class="col-sm-9">
									<input type="text" name="package[price]" class="form-control" value="{$package['price']}" placeholder="用于展示礼包价值，请填入正整数" id="price" />
								</div>
							</div>
							{if !is_store()}
							<div class="form-group"  style="display: block;">
								<label class="col-sm-2 control-label">商户结算金</label>
								<div class="col-sm-9">
									<input type="number" name="package[storemoney]" class="form-control" min="0"  value="{$package['storemoney']}" placeholder="每次核销礼包后给商户结算金额"  />
									<span class="help-block">每次核销礼包后给商户结算金额，最多保留两位小数,填0或不填则不会为商家增加余额</span>
								</div>
							</div>
							{/if}
							<div class="form-group">
								<label class="col-sm-2 control-label">时间周期类型</label>
								<div class="col-sm-9">
									<label class="radio-inline">
	                                    <input type="radio" value="1" name="datestatus" {if $package['datestatus'] == 1 || empty($package) } checked {/if}>无
	                                </label>
	                                <label class="radio-inline">
	                                    <input type="radio" value="2" name="datestatus" {if $package['datestatus'] == 2} checked {/if}>每周
	                                </label>
	                                <label class="radio-inline">
	                                    <input type="radio" value="3" name="datestatus" {if $package['datestatus'] == 3} checked {/if}>每月
	                                </label>
	                                <label class="radio-inline">
	                                    <input type="radio" value="4" name="datestatus" {if $package['datestatus'] == 4} checked {/if}>每年
	                                </label>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">使用次数</label>
								<div class="col-sm-9">
									<div class="input-group">
										<input type="tel" placeholder="请输入整数数字" id="usetimes" class="form-control" name="package[usetimes]" value="{$package[usetimes]}"/>
										<span class="input-group-addon">次</span>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">限制使用时间</label>
								<div class="col-sm-9">
									<label class="radio-inline">
										<input type="radio" value="1" id="wk" name="package[usedatestatus]" {if $package['usedatestatus'] == 1} checked {/if}>按星期
									</label>
									<label class="radio-inline">
										<input type="radio" value="2" id="dd" name="package[usedatestatus]" {if $package['usedatestatus']==2} checked {/if}>按日期
									</label>
									<label class="radio-inline">
										<input type="radio" value="0" id="cc" name="package[usedatestatus]" {if $package['usedatestatus']==0 || empty($package['usedatestatus'])} checked {/if}>关闭
									</label>
									<span class="help-block">开启后，大礼包只能在设置的时间才能使用</span>
								</div>
							</div>
							<script>
								$('#wk').click(function(){
									$('#weeke').show();
									$('#activediscount').show();
									$('#daily').hide();
								});
								$('#dd').click(function(){
									$('#weeke').hide();
									$('#activediscount').show();
									$('#daily').show();
								});
								$('#cc').click(function(){
									$('#weeke').hide();
									$('#activediscount').hide();
									$('#daily').hide();
								});
							</script>
							<div class="form-group" {if $package['usedatestatus'] != 1} style="display: none;"{/if} id="weeke">
							<label class="col-sm-2 control-label">按星期</label>
							<div class="col-sm-9">
								{if $package}
								<label class="checkbox-inline">
									<input type="checkbox" value="1" name="package[week][]" id="wk1"  /> 星期一
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="2" name="package[week][]" id="wk2"  /> 星期二
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="3" name="package[week][]" id="wk3"  /> 星期三
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="4" name="package[week][]" id="wk4"  /> 星期四
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="5" name="package[week][]" id="wk5"  /> 星期五
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="6" name="package[week][]" id="wk6"  /> 星期六
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="7" name="package[week][]" id="wk7"  /> 星期日
								</label>
								{loop $package['week'] $week}
								<script type="text/javascript">
									if({php echo $week}==1){
										$('#wk1').attr('checked','true');
									}
									if({php echo $week}==2){
										$('#wk2').attr('checked','true');
									}
									if({php echo $week}==3){
										$('#wk3').attr('checked','true');
									}
									if({php echo $week}==4){
										$('#wk4').attr('checked','true');
									}
									if({php echo $week}==5){
										$('#wk5').attr('checked','true');
									}
									if({php echo $week}==6){
										$('#wk6').attr('checked','true');
									}
									if({php echo $week}==7){
										$('#wk7').attr('checked','true');
									}

								</script>
								{/loop}
								{else}
								<label class="checkbox-inline">
									<input type="checkbox" value="1" name="package[week][]" /> 星期一
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="2" name="package[week][]" /> 星期二
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="3" name="package[week][]" /> 星期三
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="4" name="package[week][]" /> 星期四
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="5" name="package[week][]" /> 星期五
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="6" name="package[week][]" /> 星期六
								</label>
								<label class="checkbox-inline">
									<input type="checkbox" value="7" name="package[week][]" /> 星期日
								</label>
								{/if}
							</div>
						</div>
						<div class="form-group" {if $package['usedatestatus'] != 2} style="display: none;"{/if} id="daily">
						<label class="col-sm-2 control-label">按天数</label>
						<div class="col-sm-9">
							{if $package['usedatestatus'] == 2}
							<?php
								for ($i=1;$i<32;$i++ ) {
									if(in_array($i,$package['day'])){
										?>
							<label class="checkbox-inline">
								<input type="checkbox" value="{php echo $i}"  checked name="package[day][]" />{php echo $i}
							</label>
							<?php
								}else{
								?>
							<label class="checkbox-inline">
								<input type="checkbox" value="{php echo $i}"  name="package[day][]" />{php echo $i}
							</label>
							<?php
								}}
							  ?>
							{else}
							<?php
							for ($i=1;$i<32;$i++ ) {
						  ?>
							<label class="checkbox-inline">
								<input type="checkbox" value="{php echo $i}"  name="package[day][]" />{php echo $i}
							</label>
							<?php
							}
						  ?>
							{/if}
						</div>
					</div>

							<div class="form-group">
								<label class="col-sm-2 control-label">使用限制</label>
								<div class="col-sm-9">
									<input type="text" name="package[limit]" class="form-control" value="{$package['limit']}"  id="use_limit" />
									<span class="help-block">如：300元以内；酒水饮料除外；两人同行一人免单；</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">礼包限制</label>
								<div class="col-sm-9">
									<div class="input-group">
										<span class="input-group-addon">每日限</span>
										<input type="tel" placeholder="请输入整数数字" class="form-control" name="package[timeslimit]" value="{$package[timeslimit]}"/>
										<span class="input-group-addon">次，总数限</span>
										<input type="tel" placeholder="请输入整数数字" class="form-control" name="package[allnum]" value="{$package[allnum]}"/>
										<span class="input-group-addon">次</span>
									</div>
									<span class="help-block">礼包单日使用次数以及活动提供的总数量，填0或不填则无限制</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">用户限制</label>
								<div class="col-sm-9">
									<div class="input-group">
										<span class="input-group-addon">每天限</span>
										<input type="tel" placeholder="请输入整数数字" class="form-control" name="package[oplimit]" value="{$package[oplimit]}"/>
										<span class="input-group-addon">次，每周限</span>
										<input type="tel" placeholder="请输入整数数字" class="form-control" name="package[weeklimit]" value="{$package[weeklimit]}"/>
										<span class="input-group-addon">次，每月限</span>
										<input type="tel" placeholder="请输入整数数字" class="form-control" name="package[monthlimit]" value="{$package[monthlimit]}"/>
										<span class="input-group-addon">次</span>
									</div>
									<span class="help-block">每人每天、每周、每月的使用次数，填0或不填则无限制</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">等级限制</label>
								<div class="col-sm-9">
									<label class="checkbox-inline">
										<input type="checkbox" value="0" {if in_array(0,$package['level'])} checked {/if}  name="package[level][]" />{$_W['wlsetting']['halflevel']['name']}
									</label>
									{loop $levels $level}
									<label class="checkbox-inline">
										<input type="checkbox" value="{$level['id']}" {if in_array($level['id'],$package['level'])} checked {/if}  name="package[level][]" />{$level['name']}
									</label>
									{/loop}
									<span class="help-block">如果全都不勾选则默认全等级可用</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">限制开卡时间</label>
								<div class="col-sm-9">
									<label class="radio-inline" onclick="$('#timestatus').hide()">
	                                    <input type="radio" value="0" name="timestatus" {if $package['timestatus'] == 0 || empty($package) } checked {/if}>禁用
	                                </label>
									<label class="radio-inline" onclick="$('#timestatus').show()">
	                                    <input type="radio" value="1" name="timestatus" {if $package['timestatus'] == 1 } checked {/if}>启用
	                                </label>
									<div class="help-block">开启后，只有在设定时间内开卡的用户可以领取礼包</div>
								</div>
							</div>
							<div class="form-group" id="timestatus" {if $package['timestatus'] == 0 || empty($package)}  style="display: none;" {/if}>
								<label class="col-sm-2 control-label">开卡时间</label>
								<div class="col-sm-9">
									<div class="input-group">
										{php echo tpl_select_time_info('time',array('starttime'=>date('Y-m-d H:i:s',$starttime),'endtime'=>date('Y-m-d H:i:s',$endtime)));}
									</div>
								</div>
							</div>

					<div class="form-group">
						<label class="col-sm-2 control-label">限时活动</label>
						<div class="col-sm-9">
							<label class="radio-inline" onclick="$('#packtimestatus').hide()">
                                <input type="radio" value="0" name="packtimestatus" {if $package['packtimestatus'] == 0 || empty($package) } checked {/if}>禁用
                            </label>
							<label class="radio-inline" onclick="$('#packtimestatus').show()">
                                <input type="radio" value="1" name="packtimestatus" {if $package['packtimestatus'] == 1 } checked {/if}>启用
                            </label>
							<div class="help-block">开启后，只有在活动时间内才可以领取礼包</div>
						</div>
					</div>
					<div class="form-group" id="packtimestatus" {if $package['packtimestatus'] == 0 || empty($package)}  style="display: none;" {/if}>
						<label class="col-sm-2 control-label">活动时间</label>
						<div class="col-sm-9">
							<div class="input-group">
								{php echo tpl_select_time_info('datetime',array('starttime'=>date('Y-m-d H:i:s',$datestarttime),'endtime'=>date('Y-m-d H:i:s',$dateendtime)));}
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">续卡是否重置</label>
						<div class="col-sm-9">
							<label class="radio-inline">
                                <input type="radio" value="0" name="resetswitch" {if $package['resetswitch'] == 0 || empty($package) } checked {/if}>禁用
                            </label>
							<label class="radio-inline">
                                <input type="radio" value="1" name="resetswitch" {if $package['resetswitch'] == 1 } checked {/if}>启用
                            </label>
							<div class="help-block">开启后，一卡通用户续费可以重置使用次数</div>
						</div>
					</div>
					<!--<div class="form-group"  style="display: block;">
                        <label class="col-sm-2 control-label">提前预约</label>
                        <div class="col-md-4">
                            <div class="input-group">
                                <span class="input-group-addon">请提前</span>
                                <input type="tel" placeholder="可不填" class="form-control" name="package[appointment]" value="{$package[appointment]}"/>
                                <span class="input-group-addon">小时</span>
                            </div>
                        </div>
                        <label class="col-sm-2 control-label">赠送积分</label>
                        <div class="col-md-4">
                            <div class="input-group">
                                <span class="input-group-addon">核销获得</span>
                                <input type="tel" placeholder="可不填" class="form-control" name="package[integral]" value="{$package[integral]}"/>
                                <span class="input-group-addon">积分</span>
                            </div>
                        </div>
                    </div>-->
					{if !is_store()}
					<div class="form-group"  style="display: block;">
						<label class="col-sm-2 control-label">礼包排序</label>
						<div class="col-sm-9">
							<input type="tel" class="form-control" name="package[sort]" value="{$package[sort]}"/>
							<span class="help-block">请输入整数数字，序号越大，排序靠前</span>
						</div>
					</div>
					{/if}
					<div class="form-group">
						<label class="col-sm-2 control-label">使用说明</label>
						<div class="col-sm-9">
							{php echo tpl_diy_editor_create('package[describe]', $package['describe']);}
						</div>
					</div>
					{if !is_store()}
					<div class="form-group">
						<label class="col-sm-2 control-label">列表显示</label>
						<div class="col-sm-9">
							<label class="radio-inline">
                                <input type="radio" value="0" name="package[listshow]" {if $package['listshow'] == 0 || empty($package) } checked {/if}>启用
                            </label>
							<label class="radio-inline">
                                <input type="radio" value="1" name="package[listshow]" {if $package['listshow'] == 1 } checked {/if}>禁用
                            </label>
							<div class="help-block">关闭后，在首页和一卡通列表页面不会显示该礼包</div>
						</div>
					</div>
					{/if}
					<div class="form-group">
						<label class="col-sm-2 control-label">状态</label>
						<div class="col-sm-9">
							<input type="checkbox" class="js-switch" name="package[status]" {if $package['status'] == 1 || empty($package) } checked="checked" {/if}>
						</div>
					</div>
				</div>
			</div>
			<div id="modal-module-merchant" class="modal fade" tabindex="-1">
				<div class="modal-dialog" style='width: 920px;'>
					<div class="modal-content">
						<div class="modal-header">
							<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
							<h3>选取</h3></div>
						<div class="modal-body">
							<div class="row">
								<div class="input-group">
									<input type="text" class="form-control" name="keyword" value="" id="search-kwd-merchant" placeholder="请输入商家名称，不输入任何内容搜索结果为所有商家。" />
									<span class='input-group-btn'><button type="button" class="btn btn-default" onclick="search_merchant();">搜索</button></span>
								</div>
							</div>
							<div id="module-merchant" style="padding-top:5px;"></div>
						</div>
						<div class="modal-footer"><a href="#" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a></div>
					</div>
				</div>
			</div>
		</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label"></label>
			<div class="col-sm-9">
				<input type="submit" name="submit" value="提交" class="btn btn-primary min-width" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
		</form>
	</div>
</div>
<script>
$(function () {
	window.optionchanged = false;
	$('#myTab a').click(function (e) {
		e.preventDefault();//阻止a链接的跳转行为
		$(this).tab('show');//显示当前选中的链接及关联的content
	});
	var dailyflag = $('#dailyflag').val();
	//alert(dailyflag);
	if(dailyflag == 0){
		$('#discount').hide();
	}else{
		$('#discount').show();
	}
});
</script>
<script language='javascript'>
	$('#commentForm').submit(function(){
		{if !is_store()}
		if($('#namemerchant').val() == '') {
	    	$('#namemerchant').focus();
	    	util.tips("请选择商户");
			return false;
		}
		{/if}
		if($('#storetitle').val() == '') {
	    	util.tips("请填写活动名称");
	    	$('#storetitle').focus();
			return false;
		}
		if($('#usetimes').val() == '') {
	    	util.tips("请填写使用次数");
	    	$('#usetimes').focus();
			return false;
		}
		if($('#price').val() == '') {
	    	util.tips("请填写礼包价值");
	    	$('#price').focus();
			return false;
		}
//		if(!$.trim($(':input[name="package[adv]"]').val())){
//			util.tips("请至少选择一张幻灯片");
//			return false;
//		}
		if(!$.trim($(':input[name="package[describe]"]').val())){
			util.tips("请填写使用说明");
			return false;
		}
		
		return true;
	});
	
	function inspect(){
		var merchantid = $('#sidmerchant').val();
		$.post("{php echo web_url('halfcard/halfcard_web/inspect')}", { id : merchantid,type:2}, function(data){
			if(data.errno){
				util.tips("该商户已有大礼包活动");
			}else{
				if($('#storetitle').val().length < 1){
					$('#storetitle').val($('#namemerchant').val());
				}
				util.tips("操作成功");
			}
		}, 'json');
	}

	function search_merchant() {
			$("#module-merchant").html("正在搜索....")
			$.get("{php echo web_url('halfcard/halfcard_web/selectMerchant',array('type'=>2))}", {
				keyword: $.trim($('#search-kwd-merchant').val())
			}, function(dat){
				$('#module-merchant').html(dat);
			});
		}
	function remove_merchant(obj){
        $('#goodsidmerchant').val('');
        $('#namemerchant').val('');
        $('#imgmerchant').attr("src",'');
        $('#sidmerchant').val('');
       }
	function select_merchant(o) {
		var lastid = $('#sidmerchant').val();
		var fristid = $('#firstid').val();
		if (lastid != o.id) {
			$('#sidmerchant').val(o.id);
        	$('#namemerchant').val(o.storename);
        	$('#imgmerchant').attr("src",o.logo);
	    	$('#modal-module-merchant').modal('hide');
	    	inspect();
		}else{
	    	$('#modal-module-merchant').modal('hide');
		}
 	}
	function asd(){
		var dailyflag = $('#dailyflag').val();
		if (dailyflag == 0) {
			$('#discount').show();
			$('#dailyflag').val(1);
		}else{
			$('#discount').hide();
			$('#dailyflag').val(0);
		}
	}
	
</script>
{php include wl_template('common/footer');}